//
//  SDCollectionViewCellCdb.m
//  SDCycleScrollViewCdb
//
//  Created by aier on 15-3-22.
//  Copyright (c) 2015年 GSD. All rights reserved.
//


/*
 
 *********************************************************************************
 *
 * 🌟🌟🌟 新建SDCycleScrollViewCdb交流QQ群：185534916 🌟🌟🌟
 *
 * 在您使用此自动轮播库的过程中如果出现bug请及时以以下任意一种方式联系我们，我们会及时修复bug并
 * 帮您解决问题。
 * 新浪微博:GSD_iOS
 * Email : gsdios@126.com
 * GitHub: https://github.com/gsdios
 *
 * 另（我的自动布局库SDAutoLayout）：
 *  一行代码搞定自动布局！支持Cell和Tableview高度自适应，Label和ScrollView内容自适应，致力于
 *  做最简单易用的AutoLayout库。
 * 视频教程：http://www.letv.com/ptv/vplay/24038772.html
 * 用法示例：https://github.com/gsdios/SDAutoLayout/blob/master/README.md
 * GitHub：https://github.com/gsdios/SDAutoLayout
 *********************************************************************************
 
 */


#import "SDCollectionViewCellCdb.h"
#import "UIView+SDExtensionCdb.h"

@implementation SDCollectionViewCellCdb
{
    __weak UILabel *_titleLabel;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupImageView];
        [self setupTitleLabel];
        
        [self setUpUI];
        
    }
    
    return self;
}

- (void)setUpUI {
    
    self.cardView = [[UIView alloc]initWithFrame:CGRectMake(0, 200-80, kScreenW-20, 80)];
    self.cardView.backgroundColor = [UIColor redColor];
    self.cardView.backgroundColor  = RGB(68, 68, 68);
//    self.cardView.layer.cornerRadius = 8;
//    self.cardView.layer.masksToBounds = YES;
  //   self.cardView.alpha = 0.6;
    
     self.cardView.backgroundColor = [UIColor clearColor]; 
    [self.contentView addSubview:self.cardView];
    
    
    
    
    
    self.huisebeijing  = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.cardView.size.width, 80)];
    self.huisebeijing.backgroundColor = RGB(68, 68, 68);
    self.huisebeijing.alpha = 0.4;
    [self.cardView addSubview:self.huisebeijing];
    
    [self diyigekaipianView];
    
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.huisebeijing.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
   CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.huisebeijing.bounds;
   maskLayer.path = maskPath.CGPath;
   self.huisebeijing.layer.mask = maskLayer;
    
    
    
    
    
    
}


// 第一个卡片UIview
- (void)diyigekaipianView {
    
    
    self.icoiamgeView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 14, 52, 52)];
    self.icoiamgeView.backgroundColor = [UIColor yellowColor];
    self.icoiamgeView.layer.cornerRadius = 10;
    self.icoiamgeView.layer.masksToBounds = YES;
    [self.cardView addSubview:self.icoiamgeView];
    
    
    
  
    
    
    
     UILabel *netLabel = [[UILabel alloc]initWithFrame:CGRectMake( self.icoiamgeView.right+10, 11, kScreenW-100, 22)];
     netLabel.textColor  = [UIColor whiteColor];
     netLabel.text = @"游戏名称";
     netLabel.font = [UIFont systemFontOfSize:16];
    self.mingchengLabel = netLabel;
     [self.cardView addSubview:netLabel];
    
    
    
    
    self.starsBut = [UIButton  createNormalButtonWithFrame:CGRectMake(self.icoiamgeView.right+10, self.mingchengLabel.bottom+1, 15+8+3+40, 14) Image:@"stars_ico" Title:@"8.0" font:10 imageSize:CGSizeMake(8, 8)];
    [self.starsBut layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3];
    [self.starsBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.cardView addSubview: self.starsBut];
    
    
//    self.downloadBut  = [UIButton setButtonWithFrame:CGRectMake(kScreenW-58-10-30, (80-24)/2, 58, 24) Title:@"详情" Image:nil Font:15 Color:RGB(255, 255, 255) Target:nil Selector:nil];
//    self.downloadBut.backgroundColor = [UIColor  bm_colorGradientChangeWithSizeView: self.downloadBut];
//
    
    
    self.downloadBut  = [UIButton setButtonWithFrame:CGRectMake(kScreenW-98-10-30, (80-24)/2, 98, 24) Title:@"新游排行榜第 1 名" Image:nil Font:10 Color:RGB(255, 255, 255) Target:nil Selector:nil];
   //  self.downloadBut.backgroundColor = [UIColor  bm_colorGradientChangeWithSizeView: self.downloadBut];
    self.downloadBut.backgroundColor  = [UIColor clearColor];
    self.downloadBut.layer.borderWidth  =1;
    self.downloadBut.layer.borderColor = RGB(255, 255, 255).CGColor;
    self.downloadBut.layer.masksToBounds = YES;
    self.downloadBut.layer.cornerRadius = 12;
    
    
    
    
    [self.cardView addSubview:self.downloadBut];
    
    
    
    
    
    for (int i = 0; i < 3; i++) {
        
        
       UILabel *textlabel = [[UILabel alloc]initWithFrame:CGRectMake(self.icoiamgeView.right+10+i*50+i*5, self.starsBut.bottom+5, 50, 14)];
       textlabel.text = @"礼包";
       textlabel.textAlignment =  NSTextAlignmentCenter;
       textlabel.textColor = [UIColor redColor];
       textlabel.font = [UIFont systemFontOfSize:10];
       textlabel.tag = i+100;
       textlabel.backgroundColor = [UIColor redColor];
       textlabel.layer.cornerRadius = 2;
       textlabel.layer.masksToBounds = YES;
       [self.cardView addSubview:textlabel];
         textlabel.hidden = NO;
        
        
        if (i == 0 ) {
                 textlabel.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(textlabel.frame.size.width, textlabel.frame.size.height) direction:IHGradientChangeDirectionLevel startColor:RGB(255, 188, 114) endColor:RGB(255, 43, 69)];
                 textlabel.textColor = RGB(255, 255, 255);
                 
             } else if (i == 1) {
                 
                   textlabel.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(textlabel.frame.size.width, textlabel.frame.size.height) direction:IHGradientChangeDirectionLevel startColor:RGB(255, 242, 217) endColor:RGB(227, 200, 148)];
                 textlabel.textColor = RGB(61, 61, 72);
                 
             } else {
                 
                 
                   textlabel.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(textlabel.frame.size.width, textlabel.frame.size.height) direction:IHGradientChangeDirectionLevel startColor:RGB(124, 174, 255) endColor:RGB(34, 94, 255)];
                 
                  textlabel.textColor = RGB(255, 255, 255);
             }
        
        
        
    }
    
    
    
  
    
    
    
    
}








- (void)setTitleLabelBackgroundColor:(UIColor *)titleLabelBackgroundColor
{
    _titleLabelBackgroundColor = titleLabelBackgroundColor;
    _titleLabel.backgroundColor = titleLabelBackgroundColor;
}

- (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor
{
    _titleLabelTextColor = titleLabelTextColor;
    _titleLabel.textColor = titleLabelTextColor;
}

- (void)setTitleLabelTextFont:(UIFont *)titleLabelTextFont
{
    _titleLabelTextFont = titleLabelTextFont;
    _titleLabel.font = titleLabelTextFont;
}

- (void)setupImageView
{
    UIImageView *imageView = [[UIImageView alloc] init];
    _imageView = imageView;
   //  imageView.backgroundColor = [UIColor redColor];
    
    
    [self.contentView addSubview:imageView];
    
    
}

- (void)setupTitleLabel
{
    UILabel *titleLabel = [[UILabel alloc] init];
    _titleLabel = titleLabel;
    _titleLabel.hidden = YES;
    [self.contentView addSubview:titleLabel];
}

- (void)setTitle:(NSString *)title
{
    _title = [title copy];
    _titleLabel.text = [NSString stringWithFormat:@"   %@", title];
    if (_titleLabel.hidden) {
        _titleLabel.hidden = NO;
    }
}

-(void)setTitleLabelTextAlignment:(NSTextAlignment)titleLabelTextAlignment
{
    _titleLabelTextAlignment = titleLabelTextAlignment;
    _titleLabel.textAlignment = titleLabelTextAlignment;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    if (self.onlyDisplayText) {
        _titleLabel.frame = self.bounds;
    } else {
        _imageView.frame = self.bounds;
        CGFloat titleLabelW = self.sd_widthCdb;
        CGFloat titleLabelH = _titleLabelHeight;
        CGFloat titleLabelX = 0;
        CGFloat titleLabelY = self.sd_heightCdb - titleLabelH;
        _titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW, titleLabelH);
    }
}

@end
